//
//  TabBarViewController.m
//  LoveFreshBeen
//
//  Created by 辛路琦 on 16/6/11.
//  Copyright © 2016年 xinluqi. All rights reserved.
//

#import "TabBarViewController.h"
#import "NavigationViewController.h"
#import "HomeViewController.h"
#import "SuperMarketViewController.h"
#import "ShopCartViewController.h"
#import "MineViewController.h"
#import "UIImage+Render.h"
#import "LFBTabBar.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpChildViewController];
    [self setUpTabBarButton];
    
    
    LFBTabBar *tb = [LFBTabBar tabBarWithCenterBtnDidClickBlock:^(LFBTabBar *tabBar, UIButton *btn) {
        /**
         *  跳转到购物车控制器(modal)
         */
        // 购物车
        ShopCartViewController *shopCartTrendVc = [[ShopCartViewController alloc] init];
        NavigationViewController *shopCartTrendNav = [[NavigationViewController alloc] initWithRootViewController:shopCartTrendVc];
        
        [self presentViewController:shopCartTrendNav animated:YES completion:nil];
    }];
    
    [self setValue:tb forKey:@"tabBar"];
    
}

#pragma mark - 设置tabBarItem文字属性
+ (void)load
{
    // 获取全局item
    UITabBarItem *item = [UITabBarItem appearance];
    // 创建字典去描述文本
    NSMutableDictionary *dictTitleColor = [NSMutableDictionary dictionary];
    // 设置item的title在选中状态下的颜色
    dictTitleColor[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    [item setTitleTextAttributes:dictTitleColor forState:UIControlStateSelected];
    
    NSMutableDictionary *dictTitleFont = [NSMutableDictionary dictionary];
    // 设置title的字体大小
    dictTitleFont[NSFontAttributeName] = [UIFont systemFontOfSize:11];
    
    [item setTitleTextAttributes:dictTitleFont forState:UIControlStateNormal];
    
}


#pragma mark - 添加子控制器
- (void)setUpChildViewController
{
    // 首页
    HomeViewController *homeVc = [[HomeViewController alloc] init];
    NavigationViewController *homeNav = [[NavigationViewController alloc] initWithRootViewController:homeVc];
    [self addChildViewController:homeNav];
    
    // 闪电超市
    SuperMarketViewController *superMarketVc = [[SuperMarketViewController alloc] init];
    NavigationViewController *superMarketNav = [[NavigationViewController alloc] initWithRootViewController:superMarketVc];
    [self addChildViewController:superMarketNav];
    
    // 占位用
    UIViewController *vc = [[UIViewController alloc] init];
    [self addChildViewController:vc];
    
    // 我的
    MineViewController *mineVc = [[MineViewController alloc] init];
    NavigationViewController *mineNav = [[NavigationViewController alloc] initWithRootViewController:mineVc];
    [self addChildViewController:mineNav];
}

#pragma mark - 设置tabBarButton基本属性
- (void)setUpTabBarButton
{
    // 精华
    self.childViewControllers[0].tabBarItem.title = @"首页";
    self.childViewControllers[0].tabBarItem.image = [UIImage imageWithOriginal:@"v2_home"];
    self.childViewControllers[0].tabBarItem.selectedImage = [UIImage imageWithOriginal:@"v2_home_r"];
    
    // 新帖
    self.childViewControllers[1].tabBarItem.title = @"闪电超市";
    self.childViewControllers[1].tabBarItem.image = [UIImage imageWithOriginal:@"v2_order"];
    self.childViewControllers[1].tabBarItem.selectedImage = [UIImage imageWithOriginal:@"v2_order_r"];
    
    // 关注
    self.childViewControllers[2].tabBarItem.title = @"购物车";
    self.childViewControllers[2].tabBarItem.image = [UIImage imageWithOriginal:@"shopCart"];
    self.childViewControllers[2].tabBarItem.selectedImage = [UIImage imageWithOriginal:@"shopCart_r"];
    
    // 我
    self.childViewControllers[3].tabBarItem.title = @"我的";
    self.childViewControllers[3].tabBarItem.image = [UIImage imageWithOriginal:@"v2_my"];
    self.childViewControllers[3].tabBarItem.selectedImage = [UIImage imageWithOriginal:@"v2_my_r"];
    
}


@end
